package flc.ast.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import me.zhouzhuo.zzratingbar.ZzRatingBar;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class DailyRecAdapter extends StkProviderMultiAdapter<StkResBean> {

    public DailyRecAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new DailyRecProvider());
    }

    private class DailyRecProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_daily_rec;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            Glide.with(getContext()).load(bean.getThumbUrl())
                    .into((ImageView) baseViewHolder.getView(R.id.ivDailyRecItemImg));
            baseViewHolder.setText(R.id.tvDailyRecItemName, bean.getName());
            double score = (double) bean.getScore_total() / bean.getScore_count();
            String formattedNumber = String.format("%.1f", score);
            baseViewHolder.setText(R.id.tvDailyRecItemScore, formattedNumber);
            baseViewHolder.setText(R.id.tvDailyRecItemDesc, getContext().getString(R.string.desc_tip) + bean.getDesc());
            ZzRatingBar ratingBar = baseViewHolder.getView(R.id.zzratingbar);
            if (score > 8) {
                ratingBar.setRating(5);
            } else if (score > 6) {
                ratingBar.setRating(4);
            } else if (score > 4) {
                ratingBar.setRating(3);
            } else if (score > 2) {
                ratingBar.setRating(2);
            } else {
                ratingBar.setRating(1);
            }
            String type = getContext().getString(R.string.type_text);
            if (bean.getTagNameList() != null) {
                for (String s : bean.getTagNameList()) {
                    type += s + " ";
                }
            }
            baseViewHolder.setText(R.id.tvDailyRecItemType, type);
        }
    }

}
